import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from './pages/Layout.vue'
import LayoutDetail from "./pages/LayoutDetail.vue";

import Index from './pages/index.vue'
import Report from './pages/report.vue'
import FileType from './pages/filetype.vue'
import Chart from './pages/chart.vue'
import Collection from './pages/collection/index.vue'
import CollectionDetail from './pages/collection/detail.vue'

import AboutVip from './pages/aboutVip.vue'
import InviteList from './pages/inviteList.vue'
import Detail from './pages/detail.vue'
import MyOrder from './pages/myOrder.vue'
import Protocol from './pages/protocol.vue'
import Privacy from './pages/privacy.vue'
import Infringement from './pages/infringement.vue'
import NotFound from './pages/404.vue'

import UserIndex from './pages/user/index.vue'
import UserInfo from './pages/user/userinfo.vue'
import History from './pages/user/history.vue'
import Favorite from './pages/user/favorite.vue'
import Download from './pages/user/download.vue'
import Invite from './pages/user/invite.vue'
import Order from './pages/user/order.vue'

import MyRecord from './pages/myRecord.vue'
import MyCollection from './pages/myCollection.vue'




Vue.use(VueRouter)
// 解决重复点击路由报错的BUG
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  // store().dispatch('GetInfo')
  return originalPush.call(this, location).catch((err) => err)
}

const routes = [
  {
    path: '/',
    name: 'Layout',
    redirect: '/index',
    component: Layout,
    children: [
      {
        path: '/index',
        name: 'index',
        alias: '/',
        meta: {
          header: "fixed",
          footer: "fixed",
        },

        component: Index
      },
      {
        path: '/chart',
        name: 'chart',
        meta: {},
        component: Chart
      },
      {
        path: '/report',
        name: 'report',
        meta: {
          header: "fixed",
          footer: "fixed",
        },
        component: Report
      },
      {
        path: '/filetype/:id',
        name: 'filetype',
        meta: {},
        component: FileType
      },
      {
        path: '/collection',
        name: 'collection',
        meta: {},
        component: Collection
      },
      {
        path: '/collection/detail',
        name: 'collection_detail',
        meta: {},
        component: CollectionDetail
      },
      {
        path: '/aboutVip',
        name: 'aboutVip',
        meta: {
          header: "fixed",
          footer: "fixed",
        },
        component: AboutVip
      },
      {
        path: "/myCollection",
        name: "myCollection",
        mete: {
          header: "fixed",
          footer: "fixed",
        },
        component: MyCollection,
      },
      {
        path: "/myRecord",
        name: "myRecord",
        mete: {
          header: "fixed",
          footer: "fixed",
        },
        component: MyRecord,
      },
      {
        path: '/user/index',
        name: 'user_index',
        alias: '/user',
        meta: {},
        component: UserIndex
      },
      {
        path: '/user/userinfo',
        name: 'user_userinfo',
        meta: {},
        component: UserInfo
      },
      {
        path: '/user/history',
        name: 'user_history',
        meta: {},
        component: History
      },
      {
        path: '/user/download',
        name: 'user_download',
        meta: {},
        component: Download
      },
      {
        path: '/user/favorite',
        name: 'user_favorite',
        meta: {},
        component: Favorite
      },
      {
        path: '/user/invite',
        name: 'user_invite',
        meta: {},
        component: Invite
      },
      {
        path: '/user/order',
        name: 'user_order',
        meta: {},
        component: Order
      },
    ]
  },
  {
    path: "/detail",
    name: "LayoutDetail",
    component: LayoutDetail,
    children: [
      {
        //pdf详情
        path: "/detail",
        name: "detail",
        meta: {
          header: "fixed",
          footer: false,
        },
        component: Detail,
      },
    ],
  },
  {
    path: "/protocol",
    name: "protocol",
    meta: {},
    component: Protocol,
  },
  {
    path: "/privacy",
    name: "privacy",
    meta: {},
    component: Privacy,
  },
  {
    path: "/infringement",
    name: "infringement",
    meta: {},
    component: Infringement,
  },
  {
    path: "/:catchAll(.*)",
    name: 404,
    component: NotFound,
  },
]

export function createRouter() {
  return new VueRouter({
    routes,
    mode: 'history'
  })
}
